package com.jiacl.controller;

import com.jiacl.entity.JiaclArea;
import com.jiacl.entity.core.Result;
import com.jiacl.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by XiaoWei on 2017/9/1.
 */
@Controller
@RequestMapping("/area")
@ResponseBody
public class AreaController {

    @Autowired
    private AreaService areaService;

    @GetMapping("/getArea/{areaId}")
    public ResponseEntity<Result> area(@PathVariable("areaId") Long areaId) throws Exception {
        Result area = areaService.getArea(areaId);
        return ResponseEntity.ok(area);
    }
    @GetMapping("/getArea")
    public ResponseEntity<Result> areaNull() throws Exception {
        return ResponseEntity.ok(new Result());
    }

    @GetMapping("/getAreaByParent/{areaParentId}")
    public ResponseEntity<Result> getAreaParentId(@PathVariable("areaParentId") Long areaParentId) throws Exception {
        Result area = areaService.getAreaByParent(areaParentId);
        return ResponseEntity.ok(area);
    }
}
